home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr49
/
130_01.zip
/
LONG.DOC
< prev
next >
Wrap
Text File
|
1993-06-01
|
5KB
|
152 lines
LONG INTEGERS
(c) 1981 by Paul J. Gans
/* modified by SP 9/82 -
added functions: ltou(u, longform) convert low 16 bits to unsigned
utol(longform, u) convert unsigned to longform
*/
The Long Integer Package
The Long Integer Package is a collection of functions
designed to provide the users of Leor Zolman's BDS C with
the ability to manipulate long integers. This package has
been modeled upon the Floating Point Package for BDS C
written by Bob Mathias and works in a similar manner.
The package works with long integers stored as four
consecutive bytes with the least significant byte stored
at the lowest memory address. The precision maintained is
31 bits plus sign. To use the package, all long integers
should be declared as four byte char arrays. Manipulation
is by pointer to the arrays. Thus the code
char first[4], second[4], result[4];
could define three long integers.
The possible range a long integer longform may
occupy is:
-2147483648 <= longform <= 2147483647
Long integers are manipulated via the following
functions:
char *ladd(sum,addend,augend)
char sum[4], addend[4], augend[4];
adds addend and augend, stores the 32 bit signed
result in sum and returns a pointer to sum.
char *lsub(diff,minuend,subtrahend)
char diff[4], minuend[4], subtrahend[4];
subtracts subtrahend from minuend and places the
32 bit signed result in diff. A pointer to diff
is returned.
char *lmul(prod,plier,plicand)
char prod[4], plier[4], plicand[4];
plier and plicand are multiplied. The least
signficant 31 bits of the product along with the
appropriate sign bit are stored in prod. A pointer
to prod is returned.
char *ldiv(quot,dividend,divisior)
char quot[4], dividend[4], divisor[4];
dividend is divided by divisor. The least
significant 31 bits of the quotient along with the
proper sign are stored in quot. A pointer to prod
is produced. Note that no indication of overflow
is produced should it occur.
char *lmod(res,dividend,divisor)
char res[4], dividend[4], divisor[4];
dividend is divided by divisor. The positive 31
bit remainder is placed in res and a pointer to it
is returned.
char *lneg(newnum,orignum)
char newnum[4], orignum[4];
orignum is negated and placed in newnum. A pointer
to newnum is returned.
char *itol(longform,i)
char longform[4];
int i;
i is converted to long integer form and placed in
longform to which a pointer is returned.
/* note - following function modified from ver 1.0 to fix minor
bug, original didn't place value in caller's 'i', now needs address
of 'i' passed to it, it will then set i properly. 9/82 SP */
int ltoi(&i,longform)
char longform[4];
int *i;
the low order 15 bits of longform along with the
proper sign are placed in i, which value is returned.
char *atol(longform,s)
char longform[4], *s;
the '\0' terminated ASCII string s is converted to
a long integer and stored in longform to which a
pointer is returned. The proper format for s is:
any amount of white space followed by an optional
sign followed by decimal digits. The first non-
digit terminates the scan. No check is made for
overflow and improper results will result if too
many decimal digits are presented.
/* note - following modified from ver 1.0 to preserve value held
in longform. 9/82 SP */
char *ltoa(s,longform)
char longform[4], *s;
the long integer longform is converted to a '\0'
terminated ASCII string prefixed by a minus sign
if longform is negative. The string is placed in
s to which a pointer is returned. Note that the
maximum length s may attain is 12, counting 10
numerical digits, a possible minus sign, and the
terminating '\0'.
/********************************************************
following added for cnode use, 9/82 SP.
*/
char *
utol(longform, u)
char *longform;
unsigned u;
utol converts an unsigned to long form. A pointer
to the longform is returned. longform must point to an array
of 4 char.
ltou(u, longform)
unsigned *u;
char *longform;
ltou returns an unsigned integer containing the
low order 16 bits of precision of the long integer
longform. The value of this integer is placed in u and
is returned by this function. It assumes that long is
positive. BE SURE TO PASS THE ADDRESS OF THE UNSIGNED
TO THIS FUNCTION, not the unsigned itself.
/** end of additions doc **/
The Long Integer Package was written by Paul J. Gans,
Department of Chemistry, New York University, New York,
NY 10003. Phone (212) 598-2515. Bug reports welcomed.